package com.hx.template.jdbc;

import com.hx.template.jdbc.entity.User;
import com.hx.template.jdbc.jdbcTemplate.JdbcTemplate;
import com.hx.template.jdbc.jdbcTemplate.RowMapper;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

/**
 * @author Huathy
 * @date 2021-09-02 23:24
 * @description
 */
public class UserDao extends JdbcTemplate {
    public UserDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll(){
        String sql = "select * from user";
        return super.query(sql, new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws Exception {
                User user = new User();
                user.setName(rs.getString("name"));
                user.setUid(123);
                return user;
            }
        },null);
    }
}
